{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "d5eafb68-0071-444e-81fb-8743ebfd37b7",
   "metadata": {},
   "source": [
    "# Splicing from .loom tutorial"
   ]
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "This notebook assumes you have run Velocyto for your data and have a .loom file from which we can extract the splicing information.\n",
    "\n",
    "We begin by loading the necessary packages and defining the path to the .loom file."
   ],
   "id": "76feb4f8195d66f5"
  },
  {
   "cell_type": "code",
   "id": "83579d90-6216-4def-a942-6fc538b66975",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-07-17T07:20:38.905880Z",
     "start_time": "2024-07-17T07:20:35.303007Z"
    }
   },
   "source": [
    "import sys\n",
    "sys.path.append('..')\n",
    "\n",
    "import qclus as qc\n",
    "\n",
    "import warnings\n",
    "warnings.filterwarnings(\"ignore\")\n",
    "\n",
    "loompy_path = \"../../samples/sample_lq.loom\""
   ],
   "outputs": [],
   "execution_count": 1
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "Now we can extract the splicing information from the .loom file using our built-in function.",
   "id": "9ccfbaeab45055e1"
  },
  {
   "cell_type": "code",
   "id": "a4a59a62-86ef-4a12-ab66-fd7772ab66f3",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-07-17T07:25:12.888855Z",
     "start_time": "2024-07-17T07:25:12.882796Z"
    }
   },
   "source": [
    "fraction_unspliced = qc.utils.fraction_unspliced_from_loom(loompy_path)\n",
    "fraction_unspliced"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "                  fraction_unspliced\n",
       "AAACGAACATTCTCTA            0.523716\n",
       "AAACGAAAGCCGCTTG            0.505452\n",
       "AAACGCTCACGCTGTG            0.435658\n",
       "AAACGAACAACTGCTA            0.385696\n",
       "AAACGCTGTGGGTATG            0.624506\n",
       "...                              ...\n",
       "TTTGTTGGTCCTGGTG            0.595714\n",
       "TTTGTTGTCCTAAACG            0.695590\n",
       "TTTGTTGTCTACTGAG            0.496416\n",
       "TTTGTTGTCGATTGGT            0.659710\n",
       "TTTGGTTCATGGGTCC            0.179704\n",
       "\n",
       "[31670 rows x 1 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>fraction_unspliced</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>AAACGAACATTCTCTA</th>\n",
       "      <td>0.523716</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AAACGAAAGCCGCTTG</th>\n",
       "      <td>0.505452</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AAACGCTCACGCTGTG</th>\n",
       "      <td>0.435658</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AAACGAACAACTGCTA</th>\n",
       "      <td>0.385696</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AAACGCTGTGGGTATG</th>\n",
       "      <td>0.624506</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>TTTGTTGGTCCTGGTG</th>\n",
       "      <td>0.595714</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>TTTGTTGTCCTAAACG</th>\n",
       "      <td>0.695590</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>TTTGTTGTCTACTGAG</th>\n",
       "      <td>0.496416</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>TTTGTTGTCGATTGGT</th>\n",
       "      <td>0.659710</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>TTTGGTTCATGGGTCC</th>\n",
       "      <td>0.179704</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>31670 rows × 1 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 8
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "Now we save the data to a .csv file so that we can use it in the QClus pipeline.",
   "id": "d0f3a9393f3d3e8e"
  },
  {
   "cell_type": "code",
   "id": "87b2ee46",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-07-17T07:25:12.925806Z",
     "start_time": "2024-07-17T07:25:12.889679Z"
    }
   },
   "source": [
    "# save the data\n",
    "fraction_unspliced.to_csv(\"fraction_unspliced.csv\")"
   ],
   "outputs": [],
   "execution_count": 9
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
